(() => {
	let ele = {};

	ele.cardDiamond = $('#card-diamond');
	ele.wxpay = $('#wxpay');
	// ele.wdBalance = $('#wd-balance');
	ele.amount = $('#amount');
	ele.wdAll = $('#wd-all');
	ele.withdrawal = $('#withdrawal');
	ele.shouyi = $('#shouyi')
	ele.balance = $('#balance');
	ele.optionone = $('#optionone');
	ele.confirm = $('#confirm');
	ele.notopen = $('#notopen');



	hasLittle();


	// ele.notopen.onclick = ()=>{
	// 	openTips('暂未开放')
	// }



	let balance = parseFloat(getCookie('money')) || '0.00';
	init();

	function init() {
		getUserInfo(res => {
			balance = res.user_money;
			ele.balance.innerText = '￥' + balance;
		});
	}

	let options = $('.option');
	let mon = 0.3;
	for (let i = 0; i < options.length; i++) {
		options[i].onclick = (e) => {
			let that = e.target
			mon = options[i].getAttribute('data');
			// console.log(mon);
			for (let j = 0; j < options.length; j++) {
				if (that == options[j]) {
					that.classList.add('active');
				} else options[j].classList.remove('active');
			}
		}
	}

	// 确认提现
	ele.confirm.onclick = () => {
		sendWithdrawal(mon)
	}


	// ele.wxpay.onclick = () => {
	// 	openTips('即将正式上线！');
	// }

	// 全部提现功能
	// ele.wdAll.onclick = () => {
	// 	ele.amount.value = parseInt(balance);
	// }

	// // 提现
	// ele.withdrawal.onclick = () => {
	// 	let amount = parseFloat(ele.amount.value);
	// 	if (!amount) openTips('请输入提现金额');
	// 	else if (amount < 1) openTips('提现金额最少1元');
	// 	else if (amount > balance) openTips('提现金额不能大于可提现金额');
	// 	// else if (!/^\d{1,}(\.\d{1,2})?$/.test(amount)) openTips('提现金额不合法，最多支持两位小数');
	// 	else if (!/^\d{1,}$/.test(amount)) openTips('提现金额只能为整数');
	// 	else sendWithdrawal(amount);
	// }

	// 是否领过 0.3 get 
	function hasLittle() {
		let token = getCookie('token');
		let userid = getCookie('userid');
		ajax({
			url: API_PATH.HAS_LITTLE,
			methond: 'GET',
			header: {
				'Authorization': token,
			},
			success: res => {
				if (res.code == 1) {
					if (res.data == 0) {
						ele.optionone.style = 'block'
					} else if (res.data == 1) {
						ele.optionone.style = 'none'
					}
				} else {
					openTips(res.msg || '未知错误');
				}
			}
		});
	}

	// 发送提现请求
	function sendWithdrawal(amount) {
		let token = getCookie('token');
		let userid = getCookie('userid');
		ajax({
			url: API_PATH.CASH,
			methond: 'POST',
			header: {
				'Authorization': token,
			},
			data: {
				money: amount
			},
			success: res => {
				if (res.code == 1) {
					init();
				}
				openTips(res.msg);
			}
		});
	}
})();